package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.utils.FileResourceLoader;
import java.io.IOException;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;

public class BorderedTitledPane extends StackPane {
    private StringProperty title;
    private ObjectProperty<Node> content;
    private ObjectProperty<Pos> titleAlignment;

    public BorderedTitledPane() {
        this("", (Node)null);
    }

    public BorderedTitledPane(String titleString, Node contentNode) {
        this.title = new SimpleStringProperty();
        this.content = new SimpleObjectProperty();
        this.titleAlignment = new SimpleObjectProperty();

        try {
            this.getStylesheets().add(FileResourceLoader.loadURL("/views/css/BorderedTitledPane.css").toString());
        } catch (IOException var5) {
            var5.printStackTrace();
        }

        final Label titleLabel = new Label();
        titleLabel.textProperty().bind(Bindings.concat(new Object[]{this.title, " "}));
        titleLabel.getStyleClass().add("bordered-titled-title");
        this.titleAlignment.addListener(new InvalidationListener() {
            public void invalidated(Observable observable) {
                StackPane.setAlignment(titleLabel, (Pos)BorderedTitledPane.this.titleAlignment.get());
            }
        });
        final StackPane contentPane = new StackPane();
        this.getStyleClass().add("bordered-titled-border");
        this.getChildren().addAll(new Node[]{titleLabel, contentPane});
        this.content.addListener(new InvalidationListener() {
            public void invalidated(Observable observable) {
                if (BorderedTitledPane.this.content.get() == null) {
                    contentPane.getChildren().clear();
                } else {
                    if (!((Node)BorderedTitledPane.this.content.get()).getStyleClass().contains("bordered-titled-content")) {
                        ((Node)BorderedTitledPane.this.content.get()).getStyleClass().add("bordered-titled-content");
                    }

                    contentPane.getChildren().setAll(new Node[]{(Node)BorderedTitledPane.this.content.get()});
                    contentPane.requestLayout();
                }

            }
        });
        this.titleAlignment.set(Pos.TOP_LEFT);
        this.title.set(titleString);
        this.content.set(contentNode);
    }

    public String getTitle() {
        return (String)this.title.get();
    }

    public StringProperty getTitleStringProperty() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title.set(title);
    }

    public Pos getTitleAlignment() {
        return (Pos)this.titleAlignment.get();
    }

    public ObjectProperty<Pos> titleAlignmentProperty() {
        return this.titleAlignment;
    }

    public void setTitleAlignment(Pos titleAlignment) {
        this.titleAlignment.set(titleAlignment);
    }

    public Node getContent() {
        return (Node)this.content.get();
    }

    public ObjectProperty<Node> contentProperty() {
        return this.content;
    }

    public void setContent(Node content) {
        this.content.set(content);
    }
}
